package com.example.emos.wx.task;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.io.Serializable;

@Component
@Scope("prototype")
public class EmailTask implements Serializable {

	@Autowired // 自动注入JavaMailSender实例，用于发送邮件
	private JavaMailSender javaMailSender;

	@Value("${emos.email.system}")  // 从配置文件中读取emos.email.system属性的值，并注入到mailbox变量中
	private String mailbox;

	@Async
	public void sengAsync(SimpleMailMessage message){
		message.setFrom(mailbox);//设置发件人的地址为配置文件指定的地址
		javaMailSender.send(message);//使用JavaMailSender实例发送邮件
	}
}
